
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class VoitureDonnee extends JPanel {

    JLabel lblVitesseIni;
    JLabel lblVitesseIniX;
    JLabel lblVitesseIniY;
    JTextField txtVitesseIni;
    JTextField txtVitesseIniX;
    JTextField txtVitesseIniY;
    JRadioButton inconnu;
    JRadioButton inconnu2;

    public VoitureDonnee() {
        lblVitesseIni = new JLabel("Vitesse initiale:");
        txtVitesseIni = new JTextField("");
        lblVitesseIniX = new JLabel("Vitesse initiale en x:");
        lblVitesseIniY = new JLabel("Vitesse initiale en y:");
        txtVitesseIniX = new JTextField("");
        txtVitesseIniY = new JTextField("");
        inconnu = new JRadioButton("Inconnu");
        inconnu2 = new JRadioButton("Inconnu");

        inconnu.addActionListener(new GererEvenement());
        inconnu2.addActionListener(new GererEvenement());
    }

    public double getVitesseIni() {
        return Double.valueOf(txtVitesseIni.getText());
    }

    public double getVitesseIniX() {
        return Double.valueOf(txtVitesseIniX.getText());
    }

    public double getVitesseIniY() {
        return Double.valueOf(txtVitesseIniY.getText());
    }

    public void init() {
        this.setLayout(null);
        this.removeAll();

        if (Collisions.getInstance().getEstUneDim()) {
            this.setLayout(new GridLayout(1, 3));
            this.add(inconnu);
            this.add(lblVitesseIni);
            this.add(txtVitesseIni);
        } else {
            this.setLayout(new GridLayout(2, 3));
            this.add(inconnu);
            this.add(lblVitesseIniX);
            this.add(txtVitesseIniX);
            this.add(inconnu2);
            this.add(lblVitesseIniY);
            this.add(txtVitesseIniY);
        }
    }

    class GererEvenement implements ActionListener {

        public void actionPerformed(ActionEvent ae) {

            if(Collisions.getInstance().getEstUneDim()){
                if(ae.getSource()==inconnu){
                    txtVitesseIni.setEnabled(false);
                }
            }
            else{
                if(ae.getSource()==inconnu){
                    txtVitesseIniX.setEnabled(false);
                }
                else if(ae.getSource()==inconnu2){
                    txtVitesseIniY.setEnabled(false);
                }
            }
        }
    }
}
